package com.meihua.baoleyi.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.meihua.baoleyi.R;
import com.meihua.baoleyi.base.BaseActivity;
import com.meihua.baoleyi.bean.InfantAcupointBean;
import com.meihua.baoleyi.common.APIServer;
import com.meihua.baoleyi.net.NetHelper;
import com.meihua.baoleyi.utils.ToastUtil;

import java.util.TreeMap;

import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 作者：lc on 2017/10/31.
 * 邮箱：lc0607live@163.com
 */

public class ManipulationActivity extends BaseActivity {


    @Bind(R.id.iv_back)
    ImageView back;
    @Bind(R.id.text_title)
    TextView textTitle;
    @Bind(R.id.layout)
    RelativeLayout layout;
    @Bind(R.id.iv_head)
    ImageView ivHead;
    @Bind(R.id.point_name)
    TextView pointName;
    @Bind(R.id.position)
    TextView position;
    @Bind(R.id.operation)
    TextView operation;
    @Bind(R.id.effect)
    TextView effect;
    @Bind(R.id.range)
    TextView range;
    private int id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manipution);
        ButterKnife.bind(this);
        initView();
    }

    public static Intent createIntent(Context mContext, int id) {
        Intent intent = new Intent(mContext, ManipulationActivity.class);
        intent.putExtra("id", id);
        return intent;
    }

    private void initView() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        id = getIntent().getIntExtra("id", 0);
        getServerData();
    }

    public void getServerData() {
        showDialog();
        TreeMap<String, String> mTreeMap = new TreeMap<>();
        mTreeMap.put("id", id + "");
        NetHelper.post(APIServer.INFANT_ACUPOINT, mTreeMap, true, new NetHelper.HttpCallBack() {
            @Override
            public void onSuccess(String s, Call call, Response response) {
                InfantAcupointBean bean = NetHelper.getBeanForJson(InfantAcupointBean.class, s);
                InfantAcupointBean.DataBean dataBean = bean.getData();
                if (bean.getCode().equals("100")) {
                    if (!dataBean.getPoint_img().equals("")) {
                        Glide.with(getApplicationContext()).load(dataBean.getPoint_img()).error(R.mipmap.chanpin).into(ivHead);
                        pointName.setText(dataBean.getPoint_name());
                        position.setText(dataBean.getPosition());
                        operation.setText(dataBean.getOperation());
                        effect.setText(dataBean.getEffect());
                        range.setText(dataBean.getRange());
                    }
                } else {
                    ToastUtil.show(ManipulationActivity.this, bean.getMsg());
                }
                dismissDialog();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
